﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Composite.Modularity;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Composite.Events;
using Microsoft.Practices.Composite.Presentation.Events;
using Microsoft.Practices.Composite.Regions;
using Douban.Modules.Conversation.ViewModels;
using Douban.Modules.Conversation.Views;
using Douban.Core.Events;
using Douban.Api;

namespace Douban.Modules.Conversation
{
    public class ConversationModule : IModule
    {
        private readonly IUnityContainer _container;
        private readonly IEventAggregator _eventAggregator;
        private readonly DoubanService _doubanService;

        public ConversationModule(IUnityContainer container, IEventAggregator eventAggregator, DoubanService doubanService)
        {
            _container = container;
            _eventAggregator = eventAggregator;
            _doubanService = doubanService;
        }

        #region IModule Members

        public void Initialize()
        {
            RegisterViews();
            RegisterViewModels();
            RegisterConversationManager();
        }
        
        #endregion

        private void RegisterViews()
        {
            _container.RegisterType<IConversationShellView, ConversationShellView>()
                .RegisterType<IContactInfoView, ContactInfoView>()
                .RegisterType<ICaptchaView, CaptchaView>()
                .RegisterType<IConversationWorkSpaceView, ConversationWorkSpaceView>()
                .RegisterType<IChatLogView, ChatLogView>();
        }

        private void RegisterViewModels()
        {
            _container.RegisterType<IConversationShellViewModel, ConversationShellViewModel>()
                .RegisterType<IContactInfoViewModel, ContactInfoViewModel>()
                .RegisterType<ICaptchaViewModel, CaptchaViewModel>()
                .RegisterType<IConversationWorkSpaceViewModel, ConversationWorkSpaceViewModel>()
                .RegisterType<IChatLogViewModel, ChatLogViewModel>();
        }

        private void RegisterConversationManager()
        {
            _container.RegisterInstance<ConversationManager>(new ConversationManager(_container, _eventAggregator, _doubanService));
        }
    }
}
